﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using Models;
using DAL;
using WebShopAPI.Models;
using System.Web.Script.Serialization;
namespace WebShopAPI.Controllers
{
    public class gwcController : ApiController
    {
        sp_user_cartDAL gw = new sp_user_cartDAL();
        sp_ProductServcie program = new sp_ProductServcie();
        sp_goods_picsService p = new sp_goods_picsService();
        public ResponData Get(int userid)
        {
            sp_user_cart sp_Users = gw.cx().Where(p => p.user_id == userid).FirstOrDefault();
            List<gwsp> gg = new List<gwsp>();
            JavaScriptSerializer j = new JavaScriptSerializer();
            gg = j.Deserialize<List<gwsp>>(sp_Users.cart_info);
            List<goodsym> ss = new List<goodsym>();
            for (int i = 0; i < gg.Count; i++)
            {
                goodsym s = new goodsym();
                s.list = program.cx().Where(p => p.Id == gg[i].goods_id).ToList()[0];
                s.number = gg[i].amount;
                s.pic = p.GetAll().Where(p => p.goods_id == s.list.Goods_id).ToList()[0].pics_mid;
                ss.Add(s);
            }

            ResponData re = new ResponData();
            re.data = ss;
            re.meta.msg = "查询成功";
            re.meta.status = 200;
            return re;
        }
    }
    public class gwsp
    {
        public int goods_id { get; set; }
        public int amount { get; set; }
    }
    public class goodsym
    {
        public sp_Product list { get; set; }
        public string pic { get; set; }
        public int number { get; set; }
    }
}
